package com.ruoyi.eduadmin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.eduadmin.domain.ItFocus;
import com.ruoyi.eduadmin.dto.ChangeClassDto;
import com.ruoyi.eduadmin.dto.ChangeFocusDto;
import com.ruoyi.eduadmin.dto.StateDto;
import com.ruoyi.eduadmin.service.IItClassesService;
import com.ruoyi.eduadmin.service.IItFocusService;
import com.ruoyi.eduadmin.service.IItProblemTrackingRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.eduadmin.domain.ItStudentes;
import com.ruoyi.eduadmin.service.IItStudentesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 学生管理Controller
 * 
 * @author ruoyi
 * @date 2022-12-27
 */
@RestController
@RequestMapping("/studentes")
public class ItStudentesController extends BaseController
{
    @Autowired
    private IItStudentesService itStudentesService;

    @Autowired
    private IItClassesService itClassesService;

    @Autowired
    private IItFocusService itFocusService;

    /**
     * 查询学生管理列表
     */
    @RequiresPermissions("eduadmin:studentes:list")
    @GetMapping("/list")
    public TableDataInfo list(ItStudentes itStudentes)
    {
        startPage();
        List<ItStudentes> list = itStudentesService.selectItStudentesList(itStudentes);
        list.forEach(student -> {
            student.setItClasses(itClassesService.selectItClassesById(student.getClassId()));
        });
        if (itStudentes.getIsRepetition() != null && itStudentes.getIsRepetition() == true) {
            list.forEach(student -> {
                ItFocus itFocus = new ItFocus();
                itFocus = itFocusService.selectItFocusByStudentId(student.getId());
                System.out.println(itFocus);
                student.setItFocus(itFocus);
            });
        }
        return getDataTable(list);
    }

    /**
     * 导出学生管理列表
     */
    @RequiresPermissions("eduadmin:studentes:export")
    @Log(title = "学生管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItStudentes itStudentes)
    {
        List<ItStudentes> list = itStudentesService.selectItStudentesList(itStudentes);
        ExcelUtil<ItStudentes> util = new ExcelUtil<ItStudentes>(ItStudentes.class);
        util.exportExcel(response, list, "学生管理数据");
    }

    /**
     * 获取学生管理详细信息
     */
    @RequiresPermissions("eduadmin:studentes:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(itStudentesService.selectItStudentesById(id));
    }

    /**
     * 新增学生管理
     */
    @RequiresPermissions("eduadmin:studentes:add")
    @Log(title = "学生管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItStudentes itStudentes)
    {
        return toAjax(itStudentesService.insertItStudentes(itStudentes));
    }

    /**
     * 修改学生管理
     */
    @RequiresPermissions("eduadmin:studentes:edit")
    @Log(title = "学生管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItStudentes itStudentes)
    {
        return toAjax(itStudentesService.updateItStudentes(itStudentes));
    }

    /**
     * 删除学生管理
     */
    @RequiresPermissions("eduadmin:studentes:remove")
    @Log(title = "学生管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(itStudentesService.deleteItStudentesByIds(ids));
    }

    /**
     * 批量修改学生状态
     */
    @RequiresPermissions("eduadmin:studentes:edit")
    @Log(title = "学生管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody StateDto stateDto)
    {
        return toAjax(itStudentesService.changeStatus(stateDto));
    }

    /**
     * 转班
     */
    @RequiresPermissions("eduadmin:studentes:edit")
    @Log(title = "学生管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeClass")
    public AjaxResult changeClass(@RequestBody ChangeClassDto changeClassDto)
    {
        return toAjax(itStudentesService.changeClass(changeClassDto));
    }

    /**
     * 加入重点关注
     */
    @RequiresPermissions("eduadmin:studentes:edit")
    @Log(title = "学生管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeFocus")
    public AjaxResult changeFocus(@RequestBody ChangeFocusDto changeFocusDto)
    {
        return toAjax(itStudentesService.changeFocus(changeFocusDto));
    }
}
